/**
 * Live GPS Tracking Application
 * Configuration provider
 *
 * Copyright 2009, Ivar Clemens
 */

package nl.ivarclemens.config;

import javax.microedition.rms.RecordFilter;

/**
 * Finds a configuration option in a set of records.
 */
public class ConfigFilter implements RecordFilter {
    private String configOption = null;

    public ConfigFilter(String configOption)
    {
        this.configOption = configOption.toLowerCase();
    }

    public boolean matches(byte[] candidate)
    {
        String str = new String(candidate).toLowerCase();

        int sepPosition = str.indexOf("|");

        if(sepPosition < 0)
            return false;

        String fieldName = str.substring(0, sepPosition);

        if(fieldName.compareTo(configOption) == 0)
            return true;

        return false;
    }
}
